package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Letter;
import cn.wolfcode.trip.base.mapper.LetterMapper;
import cn.wolfcode.trip.base.service.ILetterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class LetterServiceImpl implements ILetterService {

    @Autowired
    private LetterMapper letterMapper;
    @Override
    public void save(Letter letter) {
        letterMapper.insert(letter);
    }

    @Override
    public void update(Letter letter) {
        letterMapper.updateByPrimaryKey(letter);
    }

    @Override
    public void delete(Long id) {
        letterMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Letter get(Long id) {
        return letterMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Letter> selectAll() {
        return letterMapper.selectAll();
    }

    // 查询未读私信
    @Override
    public int getLetterByState(Long userId) {
        return letterMapper.selectLetterByState(userId);
    }

    @Override
    public void insertLetter(Letter letter) {
        letter.setSendertime(new Date());
        letter.setState(1);
        letter.setType(3);
        letterMapper.insert(letter);
    }

    @Override
    public List<Letter> getLetters(Long userId) {
        return letterMapper.selectLetters(userId);
    }

    @Override
    public void setLetterState(int state) {
        letterMapper.updateLetterState(state);
    }

    @Override
    public List<Letter> getDoubleLetters(Long userId, Long targetId) {
        return letterMapper.selectDoubleLetters(userId,targetId);
    }
}
